<template>
  <div>
    <el-form :model="formModel" ref="form" label-width="100px">
      <el-form-item label="学科名称:" prop="name">
        <el-input v-model="formModel.name"/>
      </el-form-item>
      <el-form-item label="教师账号:" prop="tUserId">
        <el-input v-model.number="formModel.tUserId"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">确认</el-button>
        <el-button type="success" @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

export default {
  name: "SubjectAdd",
  data() {
    return {
      formModel: {
        name: '',
        tUserId: '',
      },
    }
  },
  computed: {},
  methods: {
    submit() {
      const url = '/subjects';
      const subject = this.formModel;
      this.axios.post(url, subject).then(resp => {
          if (resp.code === 200) {
            // 修改成功
            this.$message({
              type: "success",
              message: '修改成功',
              center: true,
            });
            this.$router.push({name: 'SubjectPage'});
          } else {
            this.$message({
              type: "error",
              message: resp.message,
              center: true,
            });
          }
        }
      )
    },
    cancel() {
      this.$router.go(-1);
    }
  },
}
</script>

<style scoped>

</style>